Psi5c = eye(N);
Psi5 = Psi;

for i = 2:5
    Psi5c = Psi5c + Psi ^ (i - 1);
    Psi5 = Psi5 + Psi ^ i;
end

pred_coint = Psi5c * c' + Psi5 * X2t(1:(T - 5), :)';

X5 = X2t(2:T - 4, :) + X2t(3:T - 3, :) + X2t(4:T - 2, :) + X2t(5:T - 1, :) + X2t(6:T, :);

regx = [ones(T - 5, 1), X2t(1:(T - 5), :)];
regr = ols(X5(:, dtpos), regx);
fitted_dt = regx * regr.beta;
regr = ols(X5(:, dgpos), regx);
fitted_dg = regx * regr.beta;

ts_actual_dt = X5(:, dtpos);
ts_var5y_dt = pred_coint(dtpos, :)';
ts_ols5y_dt = fitted_dt;

rmse5y_dt = [mean((ts_actual_dt - ts_var5y_dt) .^ 2), ...
                 mean((ts_actual_dt - ts_ols5y_dt) .^ 2)] * 1e4;

ts_actual_dg = X5(:, dgpos);
ts_var5y_dg = pred_coint(dgpos, :)';
ts_ols5y_dg = fitted_dg;

rmse5y_dg = [mean((ts_actual_dg - ts_var5y_dg) .^ 2), ...
                 mean((ts_actual_dg - ts_ols5y_dg) .^ 2)] * 1e4;
